﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices.ComTypes;

namespace Dazzle {
    internal class Util {
        public static string ClipboardFormatName(short format) {
            switch (format) {
                case Win32.CF_TEXT:
                    return "CF_TEXT";
                case Win32.CF_BITMAP:
                    return "CF_BITMAP";
                case Win32.CF_METAFILEPICT:
                    return "CF_METAFILEPICT";
                case Win32.CF_SYLK:
                    return "CF_SYLK";
                case Win32.CF_DIF:
                    return "CF_DIF";
                case Win32.CF_TIFF:
                    return "CF_TIFF";
                case Win32.CF_OEMTEXT:
                    return "CF_OEMTEXT";
                case Win32.CF_DIB:
                    return "CF_DIB";
                case Win32.CF_PALETTE:
                    return "CF_PALETTE";
                case Win32.CF_PENDATA:
                    return "CF_PENDATA";
                case Win32.CF_RIFF:
                    return "CF_RIFF";
                case Win32.CF_WAVE:
                    return "CF_WAVE";
                case Win32.CF_UNICODETEXT:
                    return "CF_UNICODETEXT";
                case Win32.CF_ENHMETAFILE:
                    return "CF_ENHMETAFILE";
                case Win32.CF_HDROP:
                    return "CF_HDROP";
                case Win32.CF_LOCALE:
                    return "CF_LOCALE";
                case Win32.CF_MAX:
                    return "CF_MAX";
                case Win32.CF_OWNERDISPLAY:
                    return "CF_OWNERDISPLAY";
                case Win32.CF_DSPTEXT:
                    return "CF_DSPTEXT";
                case Win32.CF_DSPBITMAP:
                    return "CF_DSPBITMAP";
                case Win32.CF_DSPMETAFILEPICT:
                    return "CF_DSPMETAFILEPICT";
                case Win32.CF_DSPENHMETAFILE:
                    return "CF_DSPENHMETAFILE";
                default: {
                        StringBuilder formatName = new StringBuilder(100);
                        if (Win32.GetClipboardFormatName((uint)format, formatName, 100) != 0)
                            return formatName.ToString();
                        else
                            return String.Format("unknown ({0})", format);
                    }
            }
        }

        public static string FormatEtcToString(FORMATETC format) {
            return String.Format("({0}, {1}, {2})",
                                 ClipboardFormatName(format.cfFormat),
                                 (DVASPECT)format.dwAspect,
                                 (TYMED)format.tymed);
        }

    }
}
